package code.example.base.util.concurrent.container;


import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

public class Node<T> {


   static  AtomicReferenceFieldUpdater nextUpdater =  AtomicReferenceFieldUpdater.newUpdater(Node.class,Node.class,"next");
    static  AtomicReferenceFieldUpdater tUpdater =  AtomicReferenceFieldUpdater.newUpdater(Node.class,Object.class,"obj");




    volatile T obj;
    volatile  Node next;

    public T get() {
        return obj;
    }

    public void set(T obj) {
        this.obj = obj;
    }

    public Node getNext() {
        return next;
    }

    public boolean  setNext(Node currentNext,Node next) {
       return  nextUpdater.compareAndSet(this,currentNext,next);
    }

    public  boolean setObj(Object srcObj,Object newObj){
        return tUpdater.compareAndSet(this,srcObj,newObj);
    }
}
